/**
 * 
 */
package com.designpattern.principle.interfacesegregation.improve;

/**
 * 例子 A类通过interface1依赖类B A类用到了B类的123方法 C类通过interface1依赖类D C类用到了D类的145方法
 * 使用接口隔离原则做UML原型图修改 修改接口1拆分为接口1(方法1) 接口2(方法2,3),接口3(方法4，方法5) B类实现接口1接口2
 * D类实现接口1接口3这样就能针对BD做接口拆分 A类使用B类方法时候，只需要按照方法传接口参数1，2 A类使用B类方法时候，只需要按照方法传接口参数1，3
 * 
 * @author zhangyang
 *
 */
public class InterfaceSegregation {

	public static void main(String[] args) {
		//A类通过方法1依赖了B类
			A a = new A();
			a.depends1(new B());
			a.depends2(new B());
	}
}

interface Interface1 {
	void operation1();
}

interface Interface2 {
	void operation2();

	void operation3();
}

interface Interface3 {
	void operation4();

	void operation5();
}

class B implements Interface1, Interface2 {

	@Override
	public void operation2() {
		// TODO Auto-generated method stub
		System.out.println("B类实现方法2");
	}

	@Override
	public void operation3() {
		// TODO Auto-generated method stub
		System.out.println("B类实现方法3");
	}

	@Override
	public void operation1() {
		// TODO Auto-generated method stub
		System.out.println("B类实现方法1");
	}

}

class D implements Interface1, Interface3 {

	@Override
	public void operation4() {
		// TODO Auto-generated method stub
		System.out.println("D类实现方法4");
	}

	@Override
	public void operation5() {
		// TODO Auto-generated method stub
		System.out.println("D类实现方法5");
	}

	@Override
	public void operation1() {
		// TODO Auto-generated method stub
		System.out.println("D类实现方法1");
	}

}

class A {
	void depends1(Interface1 in) {
		in.operation1();
	}

	void depends2(Interface2 in) {
		in.operation2();
	}

	void depends3(Interface2 in) {
		in.operation3();
	}
}

class C {
	void depends1(Interface1 i) {
		i.operation1();
	}

	void depends4(Interface3 i) {
		i.operation4();
	}

	void depends5(Interface3 i) {
		i.operation5();
	}
}
